﻿using Ajr.DigitaPlatform.DeviceAccess.Base;
using Ajri.DigitaPlatform.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ajr.DigitaPlatform.DeviceAccess.Transfer
{
    internal abstract class TransferObject
    {
        public object TUnit { get; set; }
        //集合中判断限制属性
        internal List<string> Conditions = new List<string>();

        internal virtual Result Config(List<DevicePropItemEntity> props) => new Result();

        internal virtual Result Connect(int trycount = 30) => new Result();

        internal virtual Result<List<byte>> SendAndReceived(List<byte> req, int receiveLen, int errorLen, int timeout = 5000) => null;
        internal bool ConnectState { get; set; } = false;
        // 参数：calcLen
        // 委托，作用是 在不同的地方调用SendAndReceived 计算报文长度
        internal virtual Result<List<byte>> SendAndReceived(List<byte> req, int len1, int timeout, Func<byte[], int> calcLen = null)
            => new Result<List<byte>>(false, "NULL");
        internal virtual Result Close()
        {
            this.ConnectState = false;
            return new Result();
        }

    }
}
